/**
 * Copyright - Accor - All Rights Reserved www.accorhotels.com
 */
package com.my.imq.web.root;

import java.text.DateFormat;
import java.util.ArrayList;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.AbstractSelect.Filtering;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.VerticalLayout;

/**
 * @author <a href="MABDELOUHAB">MABDELOUHAB</a>
 * created 11 janv. 2013
 * @since 
 * @version $Id$
 */
public class LeftLayout
    extends VerticalLayout

{

    private ComboBox destCmb;

    private String selectedDEstination;

    private String oldDEstination;

    //Get the new value and format it to the current locale
    private DateFormat dateFormatter = DateFormat.getDateInstance( DateFormat.SHORT );

    private InlineDateField datetime;

    /**
     * 
     */
    public LeftLayout()
    {
        destCmb = new ComboBox( "Destination", new ArrayList<String>() );

        // Set the appropriate filtering mode for this example
        destCmb.setFilteringMode( Filtering.FILTERINGMODE_CONTAINS );

        destCmb.setImmediate( true );
        destCmb.addListener( new Property.ValueChangeListener()
        {

            public void valueChange( ValueChangeEvent event )
            {
                selectedDEstination = event.getProperty().toString();

                if ( selectedDEstination != null && !selectedDEstination.isEmpty() )
                {

                }

            }

        } );

        // Disallow null selections
        destCmb.setNullSelectionAllowed( false );

        addComponent( destCmb );

        datetime = new InlineDateField( "Please select time:" );
        // Set a reasonable width
        destCmb.setWidth( datetime.getWidth(), datetime.getWidthUnits() );
        // Set the value of the PopupDateField to current date
        datetime.setValue( new java.util.Date() );

        // Set the correct resolution
        datetime.setResolution( InlineDateField.RESOLUTION_HOUR );

        // Add valuechangelistener
        datetime.addListener( new Property.ValueChangeListener()
        {

            public void valueChange( ValueChangeEvent event )
            {
                String dateOut = dateFormatter.format( event.getProperty().getValue() );
                // Show notification
                getWindow().showNotification( "date: " + dateOut );

            }

        } );
        datetime.setImmediate( true );

        addComponent( datetime );

    }

    /**
     * @return the selectedDEstination
     */
    public String getSelectedDEstination()
    {
        return selectedDEstination;
    }

}
